//
//  ComparatorManager.m
//  Documents
//
//  Created by Alex Di Mango. 
//  Copyright (c) 2012 Whardoo.com -  All rights reserved.
//

#import "ComparatorManager.h"
#import "SplittedDocumentViewController.h"

@implementation ComparatorManager

static ComparatorManager *sharedInstance = nil;

#pragma mark - Singleton methods

+(ComparatorManager *)sharedInstance
{
    if(sharedInstance == nil)
    {
        sharedInstance = [[super allocWithZone:NULL] init];
    }
    return sharedInstance;
}

-(id)init
{
    self = [super init];
    if(self)
    {
        comparing = NO;
    }
    return self;
}

-(void)dealloc
{
    [super dealloc];
}

+(id)allocWithZone:(NSZone *)zone
{
    return [[self sharedInstance] retain];
}

-(id)copyWithZone:(NSZone *)zone
{
    return self;
}

-(id)retain
{
    return self;
}

-(NSUInteger)retainCount
{
    return NSUIntegerMax;
}

-(oneway void)release
{
}

-(id)autorelease
{
    return self;
}

#pragma mark - Comparation

-(BOOL)isComparing
{
    return comparing;
}

-(void)setFirstDocument:(id<DocumentProtocol>) document
{
    firstDocument = document;
}

-(SplittedDocumentViewController *)compareWithDocument:(id<DocumentProtocol>) document
{
    secondDocument = document;
    SplittedDocumentViewController *viewController = [[[SplittedDocumentViewController alloc] initWithNibName:@"SplittedDocumentViewController" bundle:nil] autorelease];
    [viewController setFirstDocument:firstDocument];
    [viewController setSecondDocument:secondDocument];
    
    // present in a modal view controller
    viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    viewController.modalPresentationStyle = UIModalPresentationFullScreen;
    comparing = NO;
    firstDocument = nil;
    secondDocument = nil;
    return viewController;
}

-(void)startComparing
{
    comparing = YES;
}

@end
